
import java.io.IOException;
import java.net.SocketException;
import java.util.logging.Level;
import java.util.logging.Logger;



/**
 * @author User
 * @version 1.0
 * @created 10-sep-2012 11:23:26 a.m.
 */
public class EstadoMina extends Thread {

	private Bomba bomba;
	private String Estado;
	private Mina mina;
	private JavaCPN server;
	private boolean finalizar;
        //------Parte Implementada por el negro
        public static boolean stop;
        private int port;
	private String host;
        String recibirDeCPN;
        //se implementaron los metodos conectarse, recibir
        //------2 variabales agregadas-------------------------------
	public EstadoMina(){
        this.server = new JavaCPN();
	}

	public void finalize() throws Throwable {
		super.finalize();
	}
	/**
	 * 
	 * @param Mina
	 */
	public void EstadoMina(Mina mina ){

	}

	public boolean Conectar(){
		 try {
                 server.connect("localhost",9002);
            //server.connect(host, port);
            System.out.println("Server Conectado");
            stop=true;
            } catch (IOException ex) {
            System.err.println("no se encontro el host " + host);
            stop=false;
                                   }

		return stop;//stop puede ser true or false si se conecto o no
	}

	public void procesarEstado(){

	}

	private String RecibirEstado(){
                try {
                 recibirDeCPN = EncodeDecode.decodeString(server.receive());
                 System.out.println(recibirDeCPN);
                } catch (SocketException ex)
                {
                Logger.getLogger(SensorH2O.class.getName()).log(Level.SEVERE, null, ex);
                }
            return recibirDeCPN;
	}

	public void run(){
             while (this.Conectar()==false){
            this.Conectar();}
            while (finalizar==false){
            RecibirEstado();

            }
	}
}//end EstadoMina